﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Beacon.SPC
{
    /// <summary>
    /// only for spc rule to use.
    /// :(
    /// I need to implement a template version later
    /// </summary>
    public class SpcDataQueue : IEnumerable<double>
    {
        #region Members
        private Queue<double> _queue = null;
        private int _capacity;
        #endregion

        #region Contructor
        public SpcDataQueue(int capacity)
        {
            _capacity = capacity;
            if (_capacity >0 )
                _queue = new Queue<double>(_capacity);
        }
        #endregion

        #region Public functions

        public void Enqueue(double d)
        {
            if (_queue.Count >= _capacity)
            {
                _queue.Dequeue();
            }
            _queue.Enqueue(d);
        }

        public double Dequeue()
        {
            return _queue.Dequeue();
        }

        public void Clear()
        {
            _queue.Clear();
        }

        public int Count
        {
            get { return _queue.Count; }
        }

        #endregion

        #region IEnumerable<double> Members

        public IEnumerator<double> GetEnumerator()
        {
            return _queue.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        IEnumerator IEnumerable.GetEnumerator()
        {
            return _queue.GetEnumerator();
        }

        #endregion
    }

}
